import { Form, Divider, Button } from 'antd';
import React, { useEffect, useRef, useState } from 'react';
import { codeType, SecuritiesCodeC, FirstHeaderC } from '@/src/components';
import uuid from 'es6-uuid';

export default () => {
  const [form] = Form.useForm();
  const [init, setInit] = useState();
  const [key, setKey] = useState(11111);
  const refInstance = useRef();
  const onFinish = (values) => {
    console.log('Success:', values);
  };
  useEffect(() => {
    setTimeout(() => {
      setInit('101-120303');
    }, 1000);
  }, []);
  const handleclick = () => {
    refInstance.current.setSelect('113-100014');
  };
  const reset = () => {
    refInstance.current.setSelect(undefined);
  };
  const advanceSearchReset = () => {
    form.resetFields();
    setKey(uuid(16));
  };
  return (
    <div>
      <FirstHeaderC title='测试' />
      <Button onClick={handleclick}>辅值</Button>
      <Button onClick={reset}>setFieldsValue重置</Button>
      <Button onClick={advanceSearchReset}>查询组件的重置resetFields</Button>
      <Form form={form} onFinish={onFinish} key={key}>
        <SecuritiesCodeC form={form} dataIndex='code22' codeType={codeType.zq} onChange={(e) => console.log(e)} initialValue={init} onRef={(ref) => (refInstance.current = ref)} />
        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type='primary' htmlType='submit'>
            Submit 打印
          </Button>
        </Form.Item>
      </Form>
      <Divider />
    </div>
  );
};
